
from selenium import webdriver
from selenium.webdriver import ActionChains, Keys

import time

from selenium.webdriver.common.by import By

driver=webdriver.Edge()
driver.get('https://www.baidu.com/')
time.sleep(3)

# 鼠标事件
action=driver.find_element(By.ID,'x')
# 1.左击
ActionChains(driver).click(action).perform()
# 2.右击
ActionChains(driver).context_click(action).perform()
# 3.悬停
ActionChains(driver).move_to_element(action).perform()
# 4.双击
ActionChains(driver).double_click(action).perform()
# 5.按住不放
ActionChains(driver).click_and_hold(action).perform()
# 6.拖拽
ActionChains(driver).drag_and_drop(action,action).perform()
# 7.xy拖拽
ActionChains(driver).drag_and_drop_by_offset(action,xoffset=800,yoffset=60).perform()
# 8.释放
ActionChains(driver).release(action).perform()
# 9. 按轴移动
ActionChains(driver).move_by_offset(xoffset=800,yoffset=60).perform()

# 键盘事件
keys=driver.find_element(By.ID,'kw')
time.sleep(2)
# 回车事件
keys.send_keys(Keys.ENTER)
# 删除事件
keys.send_keys(Keys.DELETE)
# tab事件
keys.send_keys(Keys.TAB)
# shift事件
keys.send_keys(Keys.SHIFT)
# ctrl事件
keys.send_keys(Keys.CLEAR,'')
#.end事件
keys.send_keys(Keys.END)